home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Games / JST / sources / src / loaders / Lemmings / ripohno.c < prev   
Encoding:
C/C++ Source or Header  |  2001-03-19  |  2.1 KB  |  116 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <dos/dos.h>
  6. #include <proto/dos.h>
  7. #include <proto/exec.h>
  8. #include <exec/execbase.h>
  9. #include <exec/libraries.h>
  10. #include <exec/memory.h>
  11. #include <pragmas/dos_pragmas.h>
  12. #include <string.h>
  13.  
  14. #define DIROFFSET 0x410
  15. #define FILEOFFSET 0x1600
  16. #define BLOCKSIZE 0x10
  17. #define MAXNUMFILES 200
  18. #define MAXFILESIZE 0x14000
  19. #define MAXNAMELENGTH 0x10
  20.  
  21. struct dirstructure {
  22.     char    name[MAXNAMELENGTH];
  23.     int        length;
  24. } dir[MAXNUMFILES];
  25.  
  26.  
  27. BPTR oldlock,newlock;
  28.  
  29. FILE *fp=NULL,*fo=NULL;
  30. unsigned char temp[BLOCKSIZE+1],*temp2=NULL;
  31.  
  32. void CloseAll(char *mess)
  33.  
  34. {
  35.  
  36. if (fp) fclose(fp);
  37. if (temp2) free(temp2);
  38.  
  39. if (newlock)
  40.   {
  41.   CurrentDir(oldlock);
  42.   UnLock(newlock);
  43.   }
  44.  
  45. if (mess)
  46.     {printf("** %s\n",mess);exit(1);}
  47.     else exit(0);
  48.  
  49. }
  50.  
  51.  
  52. void main (int argc, char *argv[])
  53. {
  54. int count,count2;
  55.  
  56. printf("Oh No More Lemmings NDOS version file ripper by K. Krellwitz\nadapted by JF Fabre.\n");
  57.  
  58. if (argc<3)
  59.     {
  60.     printf ("Usage: ripono <filename> <dest-dir>\n");
  61.     exit(1);
  62.     }
  63.  
  64.  
  65. if((fp=fopen(argv[1],"r"))==NULL)
  66.     {
  67.     printf ("Cannot open file %s\n",argv[1]);
  68.     CloseAll("");
  69.     }
  70.  
  71.     /* Try to lock the specified directory */
  72.  
  73.     newlock = Lock(argv[2],ACCESS_READ);
  74.     if (!newlock) CloseAll("Couldn't lock destination directory");
  75.     oldlock = CurrentDir(newlock);
  76.  
  77. temp2=(char *)malloc(MAXFILESIZE);
  78.  
  79. if (!temp2) 
  80.     {
  81.         CloseAll("Not enough memory\n");
  82.     }
  83.  
  84.     fseek(fp,DIROFFSET,SEEK_SET);
  85.     fread(temp,BLOCKSIZE,1,fp);
  86.     count=0;
  87.  
  88. while(temp[0]!=0xff)
  89.     {
  90.     for(count2=0;temp[count2]!=0;count2++)
  91.         dir[count].name[count2]=temp[count2];
  92.     dir[count].name[count2]='\0';
  93.     dir[count].length=temp[BLOCKSIZE-3]*0x10000+
  94.                        temp[BLOCKSIZE-2]*0x100+temp[BLOCKSIZE-1];
  95.     fread(temp,BLOCKSIZE,1,fp);
  96.     if(temp[0]!=0xff)
  97.         count++;
  98.     }
  99. fseek(fp,FILEOFFSET,SEEK_SET);
  100. for(count2=0;count2<=count;count2++)
  101.     {
  102.     fread(temp2,dir[count2].length,1,fp);
  103.     if((fo=fopen(dir[count2].name,"wb"))==NULL)
  104.         {
  105.             CloseAll("Can't create destination file(s)");
  106.         }
  107.     fwrite(temp2,dir[count2].length,1,fo);
  108.     fclose(fo);
  109.     printf("Created %s %x\n",dir[count2].name,dir[count2].length);
  110.     }
  111.  
  112. printf("Done.\n");
  113. CloseAll(NULL);
  114.  
  115. }
  116.